<template>
  <div
    class="banner"
    :style="{
      backgroundColor: config.pageConfig.color,
    }"
  >
    <div
      :style="{
        marginTop: config.pageConfig.marginTop + 'px',
        marginBottom: config.pageConfig.marginBottom + 'px',
        marginLeft: config.pageConfig.margin + 'px',
        marginRight: config.pageConfig.margin + 'px',
      }"
    >
      <div class="img">
        <div class="banner-container">
          <div
            v-for="(item, idx) in config.pageConfig.imgList"
            :key="idx"
            :style="getFlex(config.pageConfig.position)"
          >
            <div
              :style="{
                borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
                borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
              }"
            >
              <img
                :style="{
                  borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                  borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                }"
                v-if="config.pageConfig.imgList[idx].imgUrl"
                :src="config.pageConfig.imgList[idx].imgUrl"
                class="banner-img"
                alt=""
              />
              <img
                :style="{
                  borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                  borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                }"
                v-else
                src="../../../../../../assets/app/bar/default_picture.png"
                class="banner-img"
                alt=""
              />
              <p
                v-if="config.pageConfig.titleShow"
                :style="{
                  fontSize: config.pageConfig.titleSize + 'px',
                  color: config.pageConfig.titleColor,
                  borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
                  borderBottomRightRadius:
                    config.pageConfig.radiusBottom + 'px',
                }"
              >
                {{ config.pageConfig.imgList[idx].title }}
              </p>
            </div>
            <p
              v-if="config.pageConfig.subtitleShow"
              :style="{
                fontSize: config.pageConfig.subtitleSize + 'px',
                color: config.pageConfig.subtitleColor,
              }"
            >
              {{ config.pageConfig.imgList[idx].subtitle }}
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "Image",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      titleShow: true,
      titleColor: "#fff",
      subtitleShow: true,
      subtitleColor: "#333",
      titleSize: 14,
      subtitleSize: 12,
      position: "1",
      color: "transparent",
      marginTop: 0,
      marginBottom: 0,
      margin: 0,
      radiusTop: 0,
      radiusBottom: 0,
      imgList: [
        {
          title: "这里是主标题",
          subtitle: "这里是副标题",
          imgUrl: "",
          name: "",
          url: "",
        },
        {
          title: "这里是主标题",
          subtitle: "这里是副标题",
          imgUrl: "",
          name: "",
          url: "",
        },
        {
          title: "这里是主标题",
          subtitle: "这里是副标题",
          imgUrl: "",
          name: "",
          url: "",
        },
      ],
    },
  },
});
console.log(config.pageConfig);
let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
const getFlex = (style: string) => {
  if (style == "1") {
    return "text-align:left;";
  } else if (style == "2") {
    return "text-align:center;";
  } else if (style == "3") {
    return "text-align:right;";
  }
};
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  overflow: hidden;
}
.img {
  .banner-container {
    width: 9999999999px;
    overflow: hidden;
    > div {
      width: 128px;
      margin-right: 12px;
      float: left;
      font-size: 13px;
      > div {
        position: relative;
        overflow: hidden;
        img {
          width: 128px;
          height: 128px;
          display: block;
          background-size: cover;
          background-repeat: no-repeat;
          background-position: 50%;
        }
        > p {
          overflow: hidden;
          position: absolute;
          top: 103px;
          height: 25px;
          width: 100%;
          line-height: 25px;
          background: linear-gradient(180deg, transparent, #9f9f9f) !important;
          color: #fff;
          padding: 0 6px;
          box-sizing: border-box;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      > p {
        height: 25px;
        width: 100%;
        line-height: 25px;
        padding: 0 6px;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}
</style>
